package com.itheima.controller;

import com.itheima.entity.Result;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("user")
public class UserController {

    @RequestMapping("getusername")
    @ResponseBody
    public Result getUsername(){
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
      if(user!=null) {
          String username = user.getUsername();
          return new Result(true,"",username);
      }
        return new Result(false,"meidengru");
    }
}
